import { getYaliUserInfo } from '../../../utils/checkAuth';
import getIn from '../../../yali-sdk/utils/getIn';
import immutable from '../../../yali-sdk/lib/immutable';
import frequentClick from '../../../yali-sdk/utils/frequentClick';
import { filterImg } from '../../imgBaseUrl';
import { MY_FANS_LIST, MY_INFORMATION ,MY_SETING} from '../../pathUrl';
Page({
    data:{
      MY_FANS_LIST,
      MY_INFORMATION,
      MY_SETING
    },
    onReady() {
        getYaliUserInfo({forceRefresh: true}).then((user) => {
           let new_user = filterImg(user, 'head_photo')
            this.setData({
                user:new_user,
                info: immutable.fromJS([
                    {
                        type: 'sex',
                        name: '性别',
                        value: user.sex,
                        isSex: true,
                        keyType: 'number',
                    },
                    {
                        type: 'height',
                        name: '身高',
                        unit: 'cm',
                        value: user.height,
                        keyType: 'digit',
                    },
                    {
                        type: 'weight',
                        name: '体重',
                        unit: 'kg',
                        value: user.weight,
                        keyType: 'digit',
                    },
                    {
                        type: 'bust',
                        name: '胸围',
                        unit: 'cm',
                        value: user.bust,
                        keyType: 'digit',
                    },
                    {
                        type: 'waist',
                        name: '腰围',
                        unit: 'cm',
                        value: user.waist,
                        keyType: 'digit',
                    },
                    {
                        type: 'hip',
                        name: '臀围',
                        unit: 'cm',
                        value: user.hip,
                        keyType: 'digit',
                    },
                ]),
            });
        });
    },
    radioChange(e) {
        console.log(e)
        const index = getIn(e, ['target', 'dataset', 'index']);
        const info = this.data.info.setIn([index, 'value'], Number(e.detail.value));
        console.log(info.toJS())
        this.setData({
            info,
        });
    },
    bindinput(e) {
        const index = getIn(e, ['target', 'dataset', 'index']);
        const info = this.data.info.setIn([index, 'value'], e.detail.value);
        this.setData({
            info,
        });
    },
    onOpenEdit() {
        frequentClick().then(() => {
            this.setData({
                isEdit: true,
                initInfo: this.data.info,
            });
        });
    },
    onOkEdit() {
        frequentClick().then(() => {
            console.log(this.data.info.toJS());
            this.setData({
                info: this.data.initInfo,
                isEdit: false,
            });
        });
    },
    onCancelEdit() {
        frequentClick().then(() => {
            this.setData({
                info: this.data.initInfo,
                isEdit: false,
            });
        });
    },
});
